<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__header">
      <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
        <a class="site-navbar__brand-lg" href="javascript:;">{{
          url.includes("charge-cabinet") ? "特电智充" :
            remark == 1 ? "中国电信" : remark == 2 ? "格林赛福" : remark == 3 ? "杭州特电" : "云禾智能"
        }}</a>
        <a class="site-navbar__brand-mini" href="javascript:;">{{
          url.includes("charge-cabinet") ? "特电智充" : remark == 1 ? "中国电信" : remark == 2 ? "格林赛福" : remark == 3 ?
            "杭州特电" : "云禾智能"
        }}</a>
      </h1>
    </div>
    <div class="site-navbar__body clearfix">
      <el-menu class="site-navbar__menu" mode="horizontal">
        <!--        <el-menu-item class="site-navbar__switch" index="0" @click="sidebarFold = !sidebarFold">-->
        <!--          <icon-svg name="zhedie"></icon-svg>-->
        <!--        </el-menu-item>-->
      </el-menu>
      <el-menu class="site-navbar__menu site-navbar__menu--right" mode="horizontal">
        <!-- <el-menu-item index="1" @click="$router.push({ name: 'theme' })">
          <template slot="title">
            <el-badge value="new">
              <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
            </el-badge>
          </template>
        </el-menu-item>
        <el-menu-item index="2">
          <el-badge value="hot">
            <a href="https://www.renren.io/" target="_blank">官方社区</a>
          </el-badge>
        </el-menu-item>
        <el-submenu index="3">
          <template slot="title">Git源码</template>
          <el-menu-item index="2-1"><a href="https://github.com/renrenio/renren-fast-vue" target="_blank">前端</a></el-menu-item>
          <el-menu-item index="2-2"><a href="https://gitee.com/renrenio/renren-fast" target="_blank">后台</a></el-menu-item>
          <el-menu-item index="2-3"><a href="https://gitee.com/renrenio/renren-generator" target="_blank">代码生成器</a></el-menu-item>
        </el-submenu>-->
        <el-menu-item class="site-navbar__avatar" index="3">
          <!--          <el-dropdown :show-timeout="0" placement="bottom">-->
          <span class="el-dropdown-link">
            <!--              <img src="~@/assets/img/avatar.png" :alt="userName">-->
            {{ user.roleName }}-{{ user.nickName }}
          </span>
          <!--            <el-dropdown-menu slot="dropdown">-->
          <!--              <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>-->
          <!--              <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>-->
          <!--            </el-dropdown-menu>-->
          <!--          </el-dropdown>-->
        </el-menu-item>

        <el-menu-item index="4" @click.native="logoutHandle()">
          <span>退出登录</span>
          <!-- <el-badge value="hot">
				    <span>退出登录</span>
          </el-badge>-->
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
  </nav>
</template>

<script>
import UpdatePassword from "./main-navbar-update-password";
import { clearLoginInfo } from "@/utils";
export default {
  data() {
    return {
      updatePassowrdVisible: false,

      programName: "",

      user: {},

      url: process.env.VUE_APP_URL
    };
  },
  components: {
    UpdatePassword,
  },
  computed: {
    navbarLayoutType: {
      get() {
        return this.$store.state.common.navbarLayoutType;
      },
    },
    sidebarFold: {
      get() {
        return this.$store.state.common.sidebarFold;
      },
      set(val) {
        this.$store.commit("common/updateSidebarFold", val);
      },
    },
    mainTabs: {
      get() {
        return this.$store.state.common.mainTabs;
      },
      set(val) {
        this.$store.commit("common/updateMainTabs", val);
      },
    },
    userName: {
      get() {
        return sessionStorage.username;
      },
    },
    roleName() {
      return sessionStorage.roleName;
    },
    name() {
      return sessionStorage.name;
    },
    remark: {
      get() {
        return sessionStorage.getItem("remark");
      },
    },
  },
  created() {
    this.getData();
  },
  methods: {

    async getData() {
      var res = await this.apis.getInfo({});
      var data = res.user || {};
      this.user = data;
      // this.programName=data.programName||'';
      // document.title=data.programName||''
    },
    // 修改密码
    updatePasswordHandle() {
      this.updatePassowrdVisible = true;
      this.$nextTick(() => {
        this.$refs.updatePassowrd.init();
      });
    },
    // 退出
    logoutHandle() {
      this.$confirm(`确定进行[退出]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // console.warn('main-navbar.vue重新加入代码')
          // this.$http.get("/sysUser/sys/exitlogin").then(res => {
          //   if (res.code === 200) {
          //     clearLoginInfo()
          //     this.$router.push({ name: 'login' })
          //   }
          // })

          sessionStorage.role = "";
          clearLoginInfo();
          sessionStorage.mainTabs_text = "";
          this.$store.commit("common/updateMainTabs", []);
          this.$router.push({
            path: "/login",
          });
        })
        .catch(() => { });
    },
  },
};
</script>
